package com.xinrui.sunnyday.job;

import com.alibaba.dubbo.config.annotation.Reference;
import com.xinrui.sunnyday.service.SetmealService;
import com.xinrui.sunnyday.utils.QiNiuUtils;
import org.springframework.stereotype.Component;

import java.util.Arrays;
import java.util.List;

@Component("cleanImgJob")
public class CleanImgJob {

    @Reference
    private SetmealService setmealService;

    public void cleanImg() {
        //查询7牛云中所有的图片
        List<String> imgIn7Niu = QiNiuUtils.listFile();
        //查询数据库中的图片
        List<String> imgInDb = setmealService.findImgs();
        //将集合中数据库的图片名删除剩下垃圾图片
        imgIn7Niu.removeAll(imgInDb);
        //将集合转换为数组
        String[] fileName = imgIn7Niu.toArray(new String[]{});
        //调用删除方法
        QiNiuUtils.removeFiles(fileName);
    }
}
